package com.xunlai.infra.permission.business.controller;

import com.xunlai.infra.permission.business.service.MembershipsGoodsService;
import com.xunlai.infra.permission.business.vo.memberships.MembershipsGoodsCreateVo;
import com.xunlai.infra.permission.business.vo.memberships.MembershipsGoodsListVo;
import com.xunlai.infra.permission.common.vo.BasePageRespVo;
import com.xunlai.infra.permission.common.vo.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liang
 * @date 8/30/23 9:42 PM
 */
@RestController
@RequestMapping("travel/manage/memberships")
public class MembershipsGoodsController {

    private MembershipsGoodsService membershipsGoodsService;

    @PostMapping("create")
    public BaseResponse<Long> create(@RequestBody MembershipsGoodsCreateVo membershipsGoodsCreateVo){
        return BaseResponse.success(membershipsGoodsService.createMembershipsGoods(membershipsGoodsCreateVo));
    }

    @RequestMapping(value = "update/{id}",method = {RequestMethod.PUT,RequestMethod.POST})
    public BaseResponse<Void> update(@PathVariable Long id, @RequestBody MembershipsGoodsCreateVo membershipsGoodsCreateVo){
        membershipsGoodsService.updateMembershipsGoods(id,membershipsGoodsCreateVo);
        return BaseResponse.success();
    }

    @DeleteMapping("delete/{id}")
    public BaseResponse<Void> delete(@PathVariable Long id){
        membershipsGoodsService.deleteMembershipsGoods(id);
        return BaseResponse.success();
    }

    @GetMapping("list")
    public BaseResponse<BasePageRespVo<MembershipsGoodsListVo>> list(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                                                     @RequestParam(required = false,defaultValue = "10") Integer pageSize){
        return BaseResponse.success(membershipsGoodsService.listMembershipsGoods(pageNum,pageSize));
    }

    @Autowired
    public void setMembershipsGoodsService(MembershipsGoodsService membershipsGoodsService) {
        this.membershipsGoodsService = membershipsGoodsService;
    }
}
